//
//  STSearchViewController.m
//  CuiBoStore
//
//  Created by 崔博 on 16/12/12.
//  Copyright © 2016年 崔博. All rights reserved.
//

#import "STSearchViewController.h"
#import "STLimitHandle.h"
#import "STGoodsListController.h"
@interface STSearchViewController ()<UISearchBarDelegate>
@property (nonatomic, strong) UISearchBar *searchBar;
@end

@implementation STSearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNaviItem];
    self.navigationItem.titleView = self.searchBar;
}
#pragma mark - mothed
- (void)setNaviItem
{
    self.view.backgroundColor = BACKGROUND_COLOR;
    self.navigationItem.leftBarButtonItem  = [UIBarButtonItem barItem:@"" title:@"" target:nil action:nil];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(back)];
}
#pragma mark - event
- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - delegate
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [STLimitHandle excuteSearchProductList:searchBar.text sucess:^(id obj) {
        STGoodsListController *listVC = [[STGoodsListController alloc] init];
        listVC.dataList = obj;
        [self.navigationController pushViewController:listVC animated:YES];
    } failed:^(id obj) {
        
    }];
    
}
#pragma mark - lazy
- (UISearchBar *)searchBar
{
    if (!_searchBar) {
       _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 40, 25)];
        _searchBar.delegate = self;
        _searchBar.placeholder = @"商品名/功效/品牌";
    }
    return _searchBar;
}
@end
